// pages/messageCode/index.js
const app = getApp()
var id;
var mid;
var msid;
var page = 1;
var pagesize = 12;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidenRemind:true,
    messageAtils: '',
    messageCodeList: '',
    messageModalput: true,
    message: ''
  },

  //获取单条留言信息
  getOneMessage: function() {
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['msid'] = id;
    var url = 'We_Community/getOneMessageLet';
    var calkdata = app.netWorkRequest(that, data, url, 'messageAtils')
  },
  //加载留言
  getMessageCodeList: function() {
    // 页数+1
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['msid'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Community/getMessageCodeList';
    var calkdata = app.netWorkRequest(that, data, url, 'messageCodeList', );
  },

  //加载更多留言列表
  getMessageCodeListLoadMore: function() {
    // 页数+1
    page = page + 1;
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['msid'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Community/getMessageCodeList';
    var f_data = that.data.messageList;
    var calkdata = app.netWorkRequestLoadMore(that, data, url, 'messageCodeList', f_data);
  },
  //回复留言
  //点击按钮痰喘指定的hiddenmodalput弹出框  
  messageModalput: function(e) {
    console.log('传递参数', e)
    msid = e.currentTarget.id;
    mid = e.currentTarget.dataset.mid;
    this.setData({
      messageModalput: !this.data.messageModalput
    })
  },
  messageComplete: function(e) {
    var msg = e.detail.value;
    var that = this;
    that.setData({
      message: msg
    })
  },
  //改变留言状态
  changeMessageState: function (nids){
    console.log('更改留言状态', nids)
    var that = this;
    var data = [];
    data['nids'] = nids;
    var url = 'We_Community/getChangeMessageState';
    var calkdata = app.netWorkRequest(that, data, url, 'changeMessage');
  },
  //取消按钮  
  cancel: function() {
    msid = '';
    mid = '';
    this.setData({
      messageModalput: true,
      message: ''
    });
  },
  //确认  
  confirm: function(e) {
    var that = this;
    var msg = that.data.message;
    if (!msg || msg == '')
      return app.promptModal('回复内容不能为空');
    if (!mid || mid == '' || !msid || msid == '')
      return app.prompt('回复失败');
    var data = [];
    data['mid'] = mid;
    data['msid'] = msid;
    data['content'] = msg;
    msid = '';
    mid = '';
    var url = 'We_Community/getAddMessageCode';
    var calkdata = app.netWorkRequest(that, data, url, 'addMessageCode')
    this.setData({
      messageModalput: true,
      message: ''
    })
  },
  hidenRemind:function(){
    var that = this;console
    that.setData({
      hidenRemind: !that.data.hidenRemind
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      hidenRemind: false
    })
    console.log('页面取值' + options.nids)
    id = options.id;
    var nids = options.nids;
    var sta = options.sta;
    if (sta == 3 && sta != '' && sta != 'undefined' && sta != undefined)
      this.changeMessageState(id);
    if (nids && nids != '' && nids != 'undefined' && nids != undefined)
      this.changeMessageState(nids);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    page = 1;
    this.getMessageCodeList();
    this.getOneMessage();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    // 显示加载图标
    wx.showLoading({
      title: '玩命加载中',
    })
    this.getMessageCodeListLoadMore();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})